//
//  ZYNCollectionReusableViewForHeader.m
//  VideoPic
//
//  Created by dllo on 16/4/5.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "ZYNCollectionReusableViewForHeader.h"

#define WIDTH self.frame.size.width
#define HEIGHT self.frame.size.height
@interface ZYNCollectionReusableViewForHeader ()
@property (nonatomic, strong) UIButton *buttonForHot;
@property (nonatomic, strong) UIButton *buttonForNewest;
@end
@implementation ZYNCollectionReusableViewForHeader
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
        
    }
    return self;
    
}
- (void)createSubViews {
    UIButton *buttonForAll = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonForAll.frame = CGRectMake(15, 10, WIDTH / 5, 30);
    [buttonForAll setTitle:@"全部 >" forState:UIControlStateNormal];
    [buttonForAll setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    buttonForAll.layer.borderWidth = 1;
    [self addSubview:buttonForAll];
    [buttonForAll addTarget:self action:@selector(handleButtonForAll:) forControlEvents:UIControlEventTouchUpInside];
    
   self.buttonForHot = [UIButton buttonWithType:UIButtonTypeCustom];
    self.buttonForHot.frame = CGRectMake(WIDTH - 130, 10, WIDTH / 6, 30);
    
    [self addSubview:_buttonForHot];
    [self.buttonForHot setTitle:@"最热" forState:UIControlStateNormal];
    [self.buttonForHot setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.buttonForHot addTarget:self action:@selector(handleButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    self.buttonForHot.tag = 100;
    [self.buttonForHot setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    
    self.buttonForNewest = [UIButton buttonWithType:UIButtonTypeCustom];
    self.buttonForNewest.frame = CGRectMake(WIDTH - 80, 10, WIDTH / 6, 30);
    [self.buttonForNewest setTitle:@"最新" forState:UIControlStateNormal];
    [self.buttonForNewest setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self addSubview:_buttonForNewest];
    [self.buttonForNewest addTarget:self action:@selector(handleButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    self.buttonForNewest.tag = 200;
    
}
- (void)handleButtonForAll:(UIButton *)button {
    
    [self.delegate handleAll];
}
- (void)handleButtonClick:(UIButton *)button {
    
    if (button.tag == 100) {
        [self.buttonForHot setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [self.buttonForNewest setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
      
    } else {
        
        [self.buttonForNewest setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [self.buttonForHot setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
    }
    [self.delegate handleHotOrNew:button];
    
}

@end
